package com.itheima.controller;

import com.itheima.entity.Student;
import com.itheima.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/stu")
public class StuController {
    @Autowired
    private StuService stuService;

    @PostMapping("/insert")
    public String insert(Student student){
//        stuService.insert(student);
        stuService.save(student);
        System.out.println("新增学生成功:"+student);
        return "新增成功";
    }

    @GetMapping("/list")
    public List<Student> list(){
        return stuService.list();
    }

    //删除学生
    @PostMapping("/delete")
    public int delete(String name){
        stuService.removeById(name);
        return 1;
    }

    //修改学生信息
    @PostMapping("/update")
    public String update(Student student){
        stuService.updateById(student);
        return "修改成功";
    }
}
